package com.ruoyi.archives.service.impl;

import java.util.List;

import com.ruoyi.archives.domain.EmerHandle;
import com.ruoyi.archives.mapper.EmerHandleMapper;
import com.ruoyi.archives.service.IEmerHandleService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 应急处置Service业务层处理
 *
 * @author wng
 * @date 2024-08-08
 */
@Service
public class EmerHandleServiceImpl implements IEmerHandleService {
    @Resource
    private EmerHandleMapper emerHandleMapper;

    /**
     * 查询应急处置
     *
     * @param id 应急处置主键
     * @return 应急处置
     */
    @Override
    public EmerHandle selectEmerHandleById(Long id) {
        EmerHandle item = emerHandleMapper.selectEmerHandleById(id);
        item.setTypeName(item.getType().getTypeName());
        return item;
    }

    /**
     * 查询应急处置列表
     *
     * @param emerHandle 应急处置
     * @return 应急处置
     */
    @Override
    public List<EmerHandle> selectEmerHandleList(EmerHandle emerHandle) {
        if (emerHandle.getParams().containsKey("createTimeStart") && emerHandle.getParams().containsKey("createTimeEnd")) {
            if (emerHandle.getParams().get("createTimeStart") != null && !"".equals(emerHandle.getParams().get("createTimeStart"))
                    && emerHandle.getParams().get("createTimeEnd") != null && !"".equals(emerHandle.getParams().get("createTimeEnd"))) {
                emerHandle.getParams().put("createTimeStart", emerHandle.getParams().get("createTimeStart") + " 00:00:00");
                emerHandle.getParams().put("createTimeEnd", emerHandle.getParams().get("createTimeEnd") + " 23:59:59");
            }

        }
        List<EmerHandle> emerHandles = emerHandleMapper.selectEmerHandleList(emerHandle);
        emerHandles.forEach(item -> {
            item.setTypeName(item.getType().getTypeName());
        });
        return emerHandles;
    }

    /**
     * 新增应急处置
     *
     * @param emerHandle 应急处置
     * @return 结果
     */
    @Override
    public int insertEmerHandle(EmerHandle emerHandle) {
        emerHandle.setCreateTime(DateUtils.getNowDate());
        return emerHandleMapper.insertEmerHandle(emerHandle);
    }

    /**
     * 修改应急处置
     *
     * @param emerHandle 应急处置
     * @return 结果
     */
    @Override
    public int updateEmerHandle(EmerHandle emerHandle) {
        emerHandle.setUpdateTime(DateUtils.getNowDate());
        return emerHandleMapper.updateEmerHandle(emerHandle);
    }

    /**
     * 批量删除应急处置
     *
     * @param ids 需要删除的应急处置主键
     * @return 结果
     */
    @Override
    public int deleteEmerHandleByIds(Long[] ids) {
        return emerHandleMapper.deleteEmerHandleByIds(ids);
    }

    /**
     * 删除应急处置信息
     *
     * @param id 应急处置主键
     * @return 结果
     */
    @Override
    public int deleteEmerHandleById(Long id) {
        return emerHandleMapper.deleteEmerHandleById(id);
    }
}
